package com.itcv;

import org.objectweb.asm.ClassVisitor;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public  class SkyWorthClassVisitor extends ClassVisitor implements Opcodes {
    public SkyWorthClassVisitor(ClassVisitor cv) {
super(ASM6,cv);
    }
    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        super.visit(version, access, name, signature, superName, interfaces);
    }

    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
        System.out.println(name);
        MethodVisitor mv = super.visitMethod(access,name,descriptor,signature,exceptions);
        if(mv != null && !"<init>".equals(name)){
            mv = new MethodAdapter(api,mv);
        }
       return mv;
    }

    class MethodAdapter extends MethodVisitor implements Opcodes {
        protected MethodAdapter(int api, MethodVisitor methodVisitor) {
            super(api, methodVisitor);
        }

        @Override
        public void visitCode() {
            System.out.println("怎么没有生效呢");
            super.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
            super.visitLdcInsn("Enter hello");
            super.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
            super.visitCode();
            //mv.visitFieldInsn();
        }
    }
}